<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2021/12/28
  Time: 14:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>基本信息</title>
</head>
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css"/>
<script type="text/javascript" src="${pageContext.request.contextPath}/layui/layui.js"></script>
<style>
    .layui-form-item label {
        font-weight: bolder;
        font-size: 16px;
    }
    #demo2{
        width: 300px;
        height: 400px;
        margin: auto;
    }
    #demo1{
        width: 300px;
        height: 400px;
    }
    #test1{

        margin-top: 20px;
    }

</style>
<body>


<script type="text/javascript">
    L2Dwidget.init();
</script>

<div class="layui-row layui-col-space1">
    <div class="layui-row layui-col-space1">
        <div class="layui-col-md5">
            <div class="grid-demo grid-demo-bg1"
                 style="font-weight: bolder;font-size: 24px;margin-top:4px;padding-left: 70px">个人信息
            </div>
            <hr>
            <div class="layui-upload" style="text-align: center">

                <div class="layui-upload-list" id="demo2" >
                    <img class="layui-upload-img" src="${sessionScope.staff.url}" id="demo1">
                    <p id="demoText"></p>
                </div>
                <%--<div style="width: 95px;">
                    <div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="demo">
                        <div class="layui-progress-bar" lay-percent=""></div>
                    </div>
                </div>--%>
<%--                <button type="button" class="layui-btn" id="test1">上传图片</button>--%>
            </div>
        </div>
        <div class="layui-col-md5">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 32px;">
                <legend>
                    基本信息
                </legend>
            </fieldset>

            <form class="layui-form" action="" lay-filter="form">
                <input type="hidden" name="password" value="${sessionScope.staff.password}">
                <div class="layui-form-item">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="staffid" value="${sessionScope.staff.staffid}" readonly="readonly"
                               style="border: none" required lay-verify="required" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="staffname" value="${sessionScope.staff.staffname}" required
                               readonly="readonly"
                               style="border: none" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">所属部门</label>
                    <div class="layui-input-inline">
                        <input type="text" name="deptid" value="" readonly="readonly"
                               required style="border: none" lay-verify="required"
                               autocomplete="off" class="layui-input" id="deptid">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">入职时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="entrytime" value="" readonly="readonly"
                               required style="border: none" lay-verify="required"
                               autocomplete="off" class="layui-input" id="entrytime">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">职位</label>
                    <div class="layui-input-inline">
                        <input type="text" name="roleid" value="" required
                               readonly="readonly"
                               style="border: none" lay-verify="required"
                               autocomplete="off" class="layui-input" id="roleid">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">身份证号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="idcard" value="${sessionScope.staff.idcard}" required
                               readonly="readonly"
                               style="border: none" lay-verify="required" readonly="readonly"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">手机号</label>
                    <div class="layui-input-inline">
                        <input type="tel" name="phone" id="" value="${sessionScope.staff.phone}" required
                               readonly="readonly"
                               style="border: none" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">地址</label>
                    <div class="layui-input-inline">
                        <input type="text" name="address" value="${sessionScope.staff.address}" required
                               readonly="readonly"
                               style="border: none" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script>

    layui.use(['table', 'jquery', 'form', 'upload'], function () {
        var table = layui.table;
        var $ = layui.jquery;
        var form = layui.form;
        var upload = layui.upload;
        var index;


        function dateStr(data){
            var y = data.year;
            // alert(y)
            var M = data.monthValue;
            var d = data.dayOfMonth;
            var H = data.hour;
            var m = data.minute;
            var s = data.second;
            var str = y + "-" + M + "-" + d + "  " + H + ":" + m + ":" +s;
            return str;
        }


        $.ajax({
            type:"post",
            url:"${pageContext.request.contextPath}/staff/getDeptRole",
            success:function (res) {
                console.log(res.data)
                $("#deptid").val(res.data.deptname);
                $("#roleid").val(res.data.rolename);
                $("#entrytime").val(dateStr(res.data.entrytime));
            }
        })
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,fileType:'images'//验证是否是图片文件
            , url: '${pageContext.request.contextPath}/upload' //改成您自己的上传接口
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code == 1) {
                    return layer.msg('上传成功');
                    //    上传成功就刷新当前头像
                }
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

        //点击取消就关闭弹框
        $("#cancel").click(function () {
            layer.close(index);
        })


    });

</script>
</html>
